﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kira.Compiler.Bods.DIs.Expressions
{
    [XmlElementMapping("LOGICAL_OP", "op", "IN")]
    public class In : BodsExpression
    {
        public ColumnReference Column
        {
            get
            {
                return this.GetElement<ColumnReference>();
            }
        }

        public IEnumerable<Constant> Values
        {
            get
            {
                return this.GetElement("IN_LIST").GetElements<Constant>();
            }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder(this.Column.ToString());
            sb.Append(" IN (");
            bool isFirst = true;
            foreach (var i in this.Values)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    sb.Append(", ");
                }
                sb.Append(i.ToString());
            }
            sb.Append(")");
            return sb.ToString();
        }
    }
}
